<!DOCTYPE html>
<html><head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <link rel="canonical" href="/unity-creator-kit-beginner-code/record/">

    <title>
        
        record | h-book
        
    </title>

    
    <link href="/css/fontawesome.min.css" rel="stylesheet">

    
    <link rel="stylesheet" href="/css/ace.min.css">

    

    

</head>
<body><nav class="navbar navbar-expand-lg navbar-dark bg-primary shadow sticky-top" id="navbarMain">
    <div class="container">
        <div>
            <a class="navbar-brand" href="/">
                
                h-book
            </a>
        </div>
    </div>
</nav>
<div class="container-fluid">
            <div class="row">

                <div class="docs-sidenav order-0 col-12 col-md-3 col-lg-2 col-xl-2 position-sticky border-right"><nav class="navbar navbar-expand-md navbar-light pl-0">
    <button class="navbar-toggler navbar-toggler-right collapsed" type="button" data-toggle="collapse" data-target="#sidenav-left-collapse" aria-controls="sidenav-left-collapse" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

     <div class="collapse navbar-collapse align-items-start flex-column" id="sidenav-left-collapse">
            <form class="form-inline my-2 my-lg-0 searchbox">
                <input class="form-control mr-sm-2 w-100" data-search-input id="search-by" type="text" placeholder="Search">
            </form>

        

         <ul class="navbar-nav flex-column pt-3">
    <li data-nav-id="/hugo/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/hugo/"><h6>Hugo</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/hugo/init/" class="nav-item my-1">
                
                
                  <a href="/hugo/init/" class="nav-link p-0">
                    init
                  </a>
                
        </li>
        <li data-nav-id="/hugo/add-page/" class="nav-item my-1">
                
                
                  <a href="/hugo/add-page/" class="nav-link p-0">
                    add-page
                  </a>
                
        </li>
        <li data-nav-id="/hugo/edit-skill/" class="nav-item my-1">
                
                
                  <a href="/hugo/edit-skill/" class="nav-link p-0">
                    edit-skill
                  </a>
                
        </li>
        <li data-nav-id="/hugo/publish/" class="nav-item my-1">
                
                
                  <a href="/hugo/publish/" class="nav-link p-0">
                    publish
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/android/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/android/"><h6>Android</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/android/install/" class="nav-item my-1">
                
                
                  <a href="/android/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/android/create-project/" class="nav-item my-1">
                
                
                  <a href="/android/create-project/" class="nav-link p-0">
                    create project
                  </a>
                
        </li>
        <li data-nav-id="/android/import-material/" class="nav-item my-1">
                
                
                  <a href="/android/import-material/" class="nav-link p-0">
                    import material
                  </a>
                
        </li>
        <li data-nav-id="/android/start-page/" class="nav-item my-1">
                
                
                  <a href="/android/start-page/" class="nav-link p-0">
                    startpage
                  </a>
                
        </li>
        <li data-nav-id="/android/i18n/" class="nav-item my-1">
                
                
                  <a href="/android/i18n/" class="nav-link p-0">
                    i18n
                  </a>
                
        </li>
        <li data-nav-id="/android/nav-flat-page/" class="nav-item my-1">
                
                
                  <a href="/android/nav-flat-page/" class="nav-link p-0">
                    nav flat page
                  </a>
                
        </li>
        <li data-nav-id="/android/activity/" class="nav-item my-1">
                
                
                  <a href="/android/activity/" class="nav-link p-0">
                    Activity
                  </a>
                
        </li>
        <li data-nav-id="/android/db/" class="nav-item my-1">
                
                
                  <a href="/android/db/" class="nav-link p-0">
                    DB
                  </a>
                
        </li>
        <li data-nav-id="/android/dialog/" class="nav-item my-1">
                
                
                  <a href="/android/dialog/" class="nav-link p-0">
                    Dialog
                  </a>
                
        </li>
        <li data-nav-id="/android/fragment/" class="nav-item my-1">
                
                
                  <a href="/android/fragment/" class="nav-link p-0">
                    Fragment
                  </a>
                
        </li>
        <li data-nav-id="/android/jetpack/" class="nav-item my-1">
                
                
                  <a href="/android/jetpack/" class="nav-link p-0">
                    Jetpack
                  </a>
                
        </li>
        <li data-nav-id="/android/material/" class="nav-item my-1">
                
                
                  <a href="/android/material/" class="nav-link p-0">
                    Material
                  </a>
                
        </li>
        <li data-nav-id="/android/storage/" class="nav-item my-1">
                
                
                  <a href="/android/storage/" class="nav-link p-0">
                    Storage
                  </a>
                
        </li>
        <li data-nav-id="/android/%E5%9B%BE%E6%A0%87/" class="nav-item my-1">
                
                
                  <a href="/android/%E5%9B%BE%E6%A0%87/" class="nav-link p-0">
                    图标
                  </a>
                
        </li>
        <li data-nav-id="/android/store/" class="nav-item my-1">
                
                
                  <a href="/android/store/" class="nav-link p-0">
                    Store
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/blender/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/blender/"><h6>Blender</h6></a>
        
    </li>
    <li data-nav-id="/bootstrap/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/bootstrap/"><h6>BootStrap</h6></a>
        
    </li>
    <li data-nav-id="/centos7/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/centos7/"><h6>Centos7</h6></a>
        
    </li>
    <li data-nav-id="/dlna/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dlna/"><h6>DLNA</h6></a>
        
    </li>
    <li data-nav-id="/docker/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/docker/"><h6>Docker</h6></a>
        
    </li>
    <li data-nav-id="/dubbo/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/dubbo/"><h6>Dubbo</h6></a>
        
    </li>
    <li data-nav-id="/ffmpeg/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/ffmpeg/"><h6>FFmpeg</h6></a>
        
    </li>
    <li data-nav-id="/git/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/git/"><h6>Git</h6></a>
        
    </li>
    <li data-nav-id="/gitbook/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gitbook/"><h6>Gitbook</h6></a>
        
    </li>
    <li data-nav-id="/gitlab/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/gitlab/"><h6>Gitlab</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/gitlab/runner/" class="nav-item my-1">
                
                
                  <a href="/gitlab/runner/" class="nav-link p-0">
                    Runner
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/gradle/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/gradle/"><h6>Gradle</h6></a>
        
    </li>
    <li data-nav-id="/java/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/java/"><h6>Java</h6></a>
        
    </li>
    <li data-nav-id="/jenkins/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/jenkins/"><h6>Jenkins</h6></a>
        
    </li>
    <li data-nav-id="/kubernetes/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/kubernetes/"><h6>Kubernetes</h6></a>
        
    </li>
    <li data-nav-id="/mybatis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis/"><h6>Mybatis</h6></a>
        
    </li>
    <li data-nav-id="/mybatis-plus/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mybatis-plus/"><h6>Mybatis Plus</h6></a>
        
    </li>
    <li data-nav-id="/mysql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/mysql/"><h6>MySQL</h6></a>
        
    </li>
    <li data-nav-id="/nodejs/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/nodejs/"><h6>Node.js</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/nodejs/npm/" class="nav-item my-1">
                
                
                  <a href="/nodejs/npm/" class="nav-link p-0">
                    NPM
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/postgresql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/postgresql/"><h6>PostgreSQL</h6></a>
        
    </li>
    <li data-nav-id="/redis/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/redis/"><h6>Redis</h6></a>
        
    </li>
    <li data-nav-id="/samba/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/samba/"><h6>Samba</h6></a>
        
    </li>
    <li data-nav-id="/sql/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/sql/"><h6>SQL</h6></a>
        
    </li>
    <li data-nav-id="/ue5/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/ue5/"><h6>UE5</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/ue5/install/" class="nav-item my-1">
                
                
                  <a href="/ue5/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/ue5/uninstall/" class="nav-item my-1">
                
                
                  <a href="/ue5/uninstall/" class="nav-link p-0">
                    uninstall
                  </a>
                
        </li>
        <li data-nav-id="/ue5/qa/" class="nav-item my-1">
                
                
                  <a href="/ue5/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity/"><h6>Unity</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity/install/" class="nav-item my-1">
                
                
                  <a href="/unity/install/" class="nav-link p-0">
                    install
                  </a>
                
        </li>
        <li data-nav-id="/unity/scene/" class="nav-item my-1">
                
                
                  <a href="/unity/scene/" class="nav-link p-0">
                    scene
                  </a>
                
        </li>
        <li data-nav-id="/unity/inspector/" class="nav-item my-1">
                
                
                  <a href="/unity/inspector/" class="nav-link p-0">
                    inspector
                  </a>
                
        </li>
        <li data-nav-id="/unity/assets/" class="nav-item my-1">
                
                
                  <a href="/unity/assets/" class="nav-link p-0">
                    assets
                  </a>
                
        </li>
        <li data-nav-id="/unity/audio-source/" class="nav-item my-1">
                
                
                  <a href="/unity/audio-source/" class="nav-link p-0">
                    audio source
                  </a>
                
        </li>
        <li data-nav-id="/unity/camera/" class="nav-item my-1">
                
                
                  <a href="/unity/camera/" class="nav-link p-0">
                    camera
                  </a>
                
        </li>
        <li data-nav-id="/unity/script/" class="nav-item my-1">
                
                
                  <a href="/unity/script/" class="nav-link p-0">
                    script
                  </a>
                
        </li>
        <li data-nav-id="/unity/prefabs/" class="nav-item my-1">
                
                
                  <a href="/unity/prefabs/" class="nav-link p-0">
                    prefabs
                  </a>
                
        </li>
        <li data-nav-id="/unity/physics/" class="nav-item my-1">
                
                
                  <a href="/unity/physics/" class="nav-link p-0">
                    physics
                  </a>
                
        </li>
        <li data-nav-id="/unity/skybox/" class="nav-item my-1">
                
                
                  <a href="/unity/skybox/" class="nav-link p-0">
                    skybox
                  </a>
                
        </li>
        <li data-nav-id="/unity/particle-system/" class="nav-item my-1">
                
                
                  <a href="/unity/particle-system/" class="nav-link p-0">
                    particle system
                  </a>
                
        </li>
        <li data-nav-id="/unity/shortcut-keys/" class="nav-item my-1">
                
                
                  <a href="/unity/shortcut-keys/" class="nav-link p-0">
                    shortcut keys
                  </a>
                
        </li>
        <li data-nav-id="/unity/qa/" class="nav-item my-1">
                
                
                  <a href="/unity/qa/" class="nav-link p-0">
                    Q&amp;A
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-beginner/"><h6>Unity 2D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-beginner/init-and-move/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/init-and-move/" class="nav-link p-0">
                    Init &amp; Move
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/map/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/map/" class="nav-link p-0">
                    Map
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/data/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/data/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/animate/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/animate/" class="nav-link p-0">
                    Data
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/bullet/" class="nav-link p-0">
                    Bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/cinemachine/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/cinemachine/" class="nav-link p-0">
                    Cinemachine
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/particle/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/particle/" class="nav-link p-0">
                    Particle
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/npc/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/npc/" class="nav-link p-0">
                    NPC
                  </a>
                
        </li>
        <li data-nav-id="/unity-2d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-2d-game-kit/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-2d-game-kit/"><h6>Unity 2D Game Kit</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-2d-game-kit/record/" class="nav-item my-1">
                
                
                  <a href="/unity-2d-game-kit/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-3d-beginner/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-3d-beginner/"><h6>Unity 3D Beginner</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-3d-beginner/init/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/level/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/level/" class="nav-link p-0">
                    Level
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/nav/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/nav/" class="nav-link p-0">
                    Nav
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/render-pipeline/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/render-pipeline/" class="nav-link p-0">
                    Render Pipeline
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/postprocessing/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/postprocessing/" class="nav-link p-0">
                    PostProcessing
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/ui/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/ui/" class="nav-link p-0">
                    UI
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/enemy/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/enemy/" class="nav-link p-0">
                    Enemy
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/sound/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/sound/" class="nav-link p-0">
                    Sound
                  </a>
                
        </li>
        <li data-nav-id="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-item my-1">
                
                
                  <a href="/unity-3d-beginner/%E5%BB%BA%E6%A8%A1%E5%B7%A5%E5%85%B7/" class="nav-link p-0">
                    建模工具
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-arpg/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-arpg/"><h6>Unity ARPG</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-arpg/init/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/role-state-machine/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/role-state-machine/" class="nav-link p-0">
                    Role State Machine
                  </a>
                
        </li>
        <li data-nav-id="/unity-arpg/api-piece/" class="nav-item my-1">
                
                
                  <a href="/unity-arpg/api-piece/" class="nav-link p-0">
                    API Piece
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-animation/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-animation/"><h6>Unity Creativecore Animation</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-animation/door/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/door/" class="nav-link p-0">
                    Door
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-animation/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-animation/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-lighting/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-lighting/"><h6>Unity Creativecore Lighting</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-lighting/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-lighting/outdoor/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-lighting/outdoor/" class="nav-link p-0">
                    Outdoor
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creativecore-shader/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creativecore-shader/"><h6>Unity Creativecore Shader</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creativecore-shader/init/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/glass/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/glass/" class="nav-link p-0">
                    Glass
                  </a>
                
        </li>
        <li data-nav-id="/unity-creativecore-shader/shader-graph/" class="nav-item my-1">
                
                
                  <a href="/unity-creativecore-shader/shader-graph/" class="nav-link p-0">
                    Shader-Graph
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-beginner-code/" class="nav-item my-1 parent haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-beginner-code/"><h6>Unity Creator Kit Beginner Code</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-beginner-code/record/" class="nav-item my-1 active">
                
                
                  <a href="/unity-creator-kit-beginner-code/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-creator-kit-fps/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-creator-kit-fps/"><h6>Unity Creator Kit FPS</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-creator-kit-fps/record/" class="nav-item my-1">
                
                
                  <a href="/unity-creator-kit-fps/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-mythirdperson/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-mythirdperson/"><h6>Unity My Third Person</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-mythirdperson/init/" class="nav-item my-1">
                
                
                  <a href="/unity-mythirdperson/init/" class="nav-link p-0">
                    Init
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-playground/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-playground/"><h6>Unity Playground</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-playground/record/" class="nav-item my-1">
                
                
                  <a href="/unity-playground/record/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-ui/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-ui/"><h6>Unity UI</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-ui/init/" class="nav-item my-1">
                
                
                  <a href="/unity-ui/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/unity-vfx/" class="nav-item my-1 haschildren
        ">
        
        
          <a class="nav-link p-0" href="/unity-vfx/"><h6>Unity VFX</h6></a>
        
        <ul class="list-unstyled ml-2">
        <li data-nav-id="/unity-vfx/init/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/init/" class="nav-link p-0">
                    record
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/bullet/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/bullet/" class="nav-link p-0">
                    bullet
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rain/" class="nav-link p-0">
                    rain
                  </a>
                
        </li>
        <li data-nav-id="/unity-vfx/rock-rain/" class="nav-item my-1">
                
                
                  <a href="/unity-vfx/rock-rain/" class="nav-link p-0">
                    Rock Rain
                  </a>
                
        </li>
        </ul>
    </li>
    <li data-nav-id="/vue/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/vue/"><h6>Vue</h6></a>
        
    </li>
    <li data-nav-id="/web/" class="nav-item my-1
        ">
        
        
          <a class="nav-link p-0" href="/web/"><h6>Web</h6></a>
        
    </li>
        </ul>
    </div>
</nav>


</div>
                <div class="docs-toc large order-lg-2 order-md-0 order-xs-1 col-12 col-lg-2 col-xl-2 position-sticky border-left"><div class="docs-toc">
	<nav id="TableOfContents">
  <ul>
    <li><a href="#导入">导入</a></li>
    <li><a href="#potionspawner-脚本">PotionSpawner 脚本</a></li>
    <li><a href="#potionloot-预制件">PotionLoot 预制件</a></li>
    <li><a href="#loot-脚本">Loot 脚本</a></li>
  </ul>
</nav>
</div>
</div>
                <div class="main col-12 order-1 col-md-9 col-lg-10 col-xl-8 py-3">
                

<div class="d-flex flex-column">
    <h1 class="js-title">record</h1>
    <div class="d-flex align-items-center">
        
    </div>
</div>

<hr>


<p>2024.08.19</p>
<h2 id="导入">导入</h2>
<ol>
<li>使用 2022.3.40f1</li>
<li>新建 3D 工程</li>
<li>将工程拖拽到 Assets</li>
<li>允许导入和升级依赖模块</li>
</ol>
<p>得如下结构</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-txt" data-lang="txt"><span style="display:flex;"><span>- Asssets
</span></span><span style="display:flex;"><span>  - Creator Kit - Beginner Code
</span></span><span style="display:flex;"><span>  - Resources
</span></span><span style="display:flex;"><span>  - Scenes
</span></span><span style="display:flex;"><span>  - TutorialInfo
</span></span></code></pre></div><h2 id="potionspawner-脚本">PotionSpawner 脚本</h2>
<p>在 Hierarchy/LevelDesign 下有个 PotionSpawner 对象，挂载了 Scripts\Tutorial\SpawnerSample.cs 脚本。可以将里面的 2 定义为 public 的变量，这样就能实现多大圆上去生成模型。另外存在重复逻辑，可以用方法封装</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#00a8c8">using</span> <span style="color:#111">UnityEngine</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">using</span> <span style="color:#111">CreatorKitCode</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">SpawnerSample</span> <span style="color:#111">:</span> <span style="color:#111">MonoBehaviour</span> <span style="color:#75715e">// 模型生成器</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">GameObject</span> <span style="color:#111">ObjectToSpawn</span><span style="color:#111">;</span> <span style="color:#75715e">// 生成对象的引用，本游戏里传入的 PotionLoot 模型</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">int</span> <span style="color:#111">angle</span> <span style="color:#111">=</span> <span style="color:#ae81ff">15</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Vector3</span> <span style="color:#111">spawnPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span><span style="color:#111">;</span> <span style="color:#75715e">// 生成器位置</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Vector3.right 1 0 0 。这里的 * 是由UnityEngine做了运算符重载的</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Vector3</span> <span style="color:#111">direction</span> <span style="color:#111">=</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">Euler</span><span style="color:#111">(</span><span style="color:#ae81ff">0</span><span style="color:#111">,</span> <span style="color:#111">angle</span><span style="color:#111">,</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">right</span><span style="color:#111">;</span> <span style="color:#75715e">// 按指定方向旋转角度（向量）</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">spawnPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span> <span style="color:#111">+</span> <span style="color:#111">direction</span> <span style="color:#111">*</span> <span style="color:#ae81ff">2</span><span style="color:#111">;</span> <span style="color:#75715e">// 基于生成器位置确定最终坐标</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// Quaternion.identity 表示一个旋转角度为度的四元数常量。四元数是一种用于表示旋转的数学工具，它可以更有效地进行旋转计算。通常用于初始化旋转变量或将物体旋转归零。   </span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instantiate</span><span style="color:#111">(</span><span style="color:#111">ObjectToSpawn</span><span style="color:#111">,</span> <span style="color:#111">spawnPosition</span><span style="color:#111">,</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">identity</span><span style="color:#111">);</span> <span style="color:#75715e">// 创建对象</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">angle</span> <span style="color:#111">=</span> <span style="color:#ae81ff">55</span><span style="color:#111">;</span> <span style="color:#75715e">// 第二个对象同理，实现模型生成器为中心画圆，圆上取点则为创建对象的坐标（算法不是描述的这样，只是结果相同）</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">direction</span> <span style="color:#111">=</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">Euler</span><span style="color:#111">(</span><span style="color:#ae81ff">0</span><span style="color:#111">,</span> <span style="color:#111">angle</span><span style="color:#111">,</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">right</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">spawnPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span> <span style="color:#111">+</span> <span style="color:#111">direction</span> <span style="color:#111">*</span> <span style="color:#ae81ff">2</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instantiate</span><span style="color:#111">(</span><span style="color:#111">ObjectToSpawn</span><span style="color:#111">,</span> <span style="color:#111">spawnPosition</span><span style="color:#111">,</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">identity</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">angle</span> <span style="color:#111">=</span> <span style="color:#ae81ff">95</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">direction</span> <span style="color:#111">=</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">Euler</span><span style="color:#111">(</span><span style="color:#ae81ff">0</span><span style="color:#111">,</span> <span style="color:#111">angle</span><span style="color:#111">,</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">right</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">spawnPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span> <span style="color:#111">+</span> <span style="color:#111">direction</span> <span style="color:#111">*</span> <span style="color:#ae81ff">2</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instantiate</span><span style="color:#111">(</span><span style="color:#111">ObjectToSpawn</span><span style="color:#111">,</span> <span style="color:#111">spawnPosition</span><span style="color:#111">,</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">identity</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#00a8c8">using</span> <span style="color:#111">UnityEngine</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">using</span> <span style="color:#111">CreatorKitCode</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">SpawnerSample</span> <span style="color:#111">:</span> <span style="color:#111">MonoBehaviour</span> 
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">GameObject</span> <span style="color:#111">ObjectToSpawn</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">radius</span> <span style="color:#111">=</span> <span style="color:#ae81ff">2</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instance</span><span style="color:#111">(</span><span style="color:#ae81ff">15</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instance</span><span style="color:#111">(</span><span style="color:#ae81ff">55</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instance</span><span style="color:#111">(</span><span style="color:#ae81ff">95</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">private</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Instance</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">angle</span><span style="color:#111">)</span> <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Vector3</span> <span style="color:#111">direction</span> <span style="color:#111">=</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">Euler</span><span style="color:#111">(</span><span style="color:#ae81ff">0</span><span style="color:#111">,</span> <span style="color:#111">angle</span><span style="color:#111">,</span> <span style="color:#ae81ff">0</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">right</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Vector3</span> <span style="color:#111">spawnPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span> <span style="color:#111">+</span> <span style="color:#111">direction</span> <span style="color:#111">*</span> <span style="color:#111">radius</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Instantiate</span><span style="color:#111">(</span><span style="color:#111">ObjectToSpawn</span><span style="color:#111">,</span> <span style="color:#111">spawnPosition</span><span style="color:#111">,</span> <span style="color:#111">Quaternion</span><span style="color:#111">.</span><span style="color:#111">identity</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="potionloot-预制件">PotionLoot 预制件</h2>
<p>模型挂载 Loot 脚本，传递 Item 参数是来自 Assets/Creator Kit - Beginner Code/Prefabs/ItemDatabase/Potion</p>
<p>Potion 包含</p>
<ul>
<li>Item Sprite: Icon_Potion</li>
<li>Item Name: Health Potion</li>
<li>Description:</li>
<li>World Object Prefab: Potion_Prefab // 药瓶模型</li>
<li>Add new Effect:</li>
<li>Script: AddHealthUsageEffect</li>
<li>Description: Add 20% of health
: Health Purcentage A: 20</li>
</ul>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#75715e">// https://docs.unity3d.com/cn/2022.3/Manual/class-ScriptableObject.html</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">Item</span> <span style="color:#111">:</span> <span style="color:#111">ScriptableObject</span> <span style="color:#75715e">// UnityEngine.ScriptableObject 可独立于类实例来保存大量数据的数据容器，所有预制件的引用访问一个数据副本</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">string</span> <span style="color:#111">ItemName</span><span style="color:#111">;</span> <span style="color:#75715e">// 物品名称</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">Sprite</span> <span style="color:#111">ItemSprite</span><span style="color:#111">;</span> <span style="color:#75715e">// 精灵图</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">string</span> <span style="color:#111">Description</span><span style="color:#111">;</span> <span style="color:#75715e">// 描述</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">GameObject</span> <span style="color:#111">WorldObjectPrefab</span><span style="color:#111">;</span> <span style="color:#75715e">// 预制体</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">virtual</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">UsedBy</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">user</span><span style="color:#111">)</span> <span style="color:#75715e">// 使用物品</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">return</span> <span style="color:#00a8c8">false</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">virtual</span> <span style="color:#00a8c8">string</span> <span style="color:#111">GetDescription</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">return</span> <span style="color:#111">Description</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#75af00">
</span></span></span><span style="display:flex;"><span><span style="color:#75af00">[CreateAssetMenu(fileName = &#34;UsableItem&#34;, menuName = &#34;Beginner Code/Usable Item&#34;, order = -999)]</span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">UsableItem</span> <span style="color:#111">:</span> <span style="color:#111">Item</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">UsageEffect</span> <span style="color:#111">:</span> <span style="color:#111">ScriptableObject</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">string</span> <span style="color:#111">Description</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">Use</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">user</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">List</span><span style="color:#111">&lt;</span><span style="color:#111">UsageEffect</span><span style="color:#111">&gt;</span> <span style="color:#111">UsageEffects</span><span style="color:#111">;</span> <span style="color:#75715e">// 一个物品可能有多种效果</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">UsedBy</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">user</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">bool</span> <span style="color:#111">wasUsed</span> <span style="color:#111">=</span> <span style="color:#00a8c8">false</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">foreach</span> <span style="color:#111">(</span><span style="color:#00a8c8">var</span> <span style="color:#111">effect</span> <span style="color:#00a8c8">in</span> <span style="color:#111">UsageEffects</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">wasUsed</span> <span style="color:#111">|=</span> <span style="color:#111">effect</span><span style="color:#111">.</span><span style="color:#111">Use</span><span style="color:#111">(</span><span style="color:#111">user</span><span style="color:#111">);</span> <span style="color:#75715e">// 或等于。有一个 true 则为 true</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">return</span> <span style="color:#111">wasUsed</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">string</span> <span style="color:#111">GetDescription</span><span style="color:#111">()</span> <span style="color:#75715e">// 补充说明</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">string</span> <span style="color:#111">description</span> <span style="color:#111">=</span> <span style="color:#00a8c8">base</span><span style="color:#111">.</span><span style="color:#111">GetDescription</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">if</span><span style="color:#111">(!</span><span style="color:#00a8c8">string</span><span style="color:#111">.</span><span style="color:#111">IsNullOrWhiteSpace</span><span style="color:#111">(</span><span style="color:#111">description</span><span style="color:#111">))</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">description</span> <span style="color:#111">+=</span> <span style="color:#d88200">&#34;\n&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">else</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">description</span> <span style="color:#111">=</span> <span style="color:#d88200">&#34;&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">foreach</span> <span style="color:#111">(</span><span style="color:#00a8c8">var</span> <span style="color:#111">effect</span> <span style="color:#00a8c8">in</span> <span style="color:#111">UsageEffects</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">description</span> <span style="color:#111">+=</span> <span style="color:#111">effect</span><span style="color:#111">.</span><span style="color:#111">Description</span> <span style="color:#111">+</span> <span style="color:#d88200">&#34;\n&#34;</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">return</span> <span style="color:#111">description</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">AddHealthUsageEffect</span> <span style="color:#111">:</span> <span style="color:#111">UsableItem</span><span style="color:#111">.</span><span style="color:#111">UsageEffect</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">int</span> <span style="color:#111">HealthPurcentageAmount</span> <span style="color:#111">=</span> <span style="color:#ae81ff">20</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">Use</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">user</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">if</span> <span style="color:#111">(</span><span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#111">Stats</span><span style="color:#111">.</span><span style="color:#111">CurrentHealth</span> <span style="color:#111">==</span> <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#111">Stats</span><span style="color:#111">.</span><span style="color:#111">stats</span><span style="color:#111">.</span><span style="color:#111">health</span><span style="color:#111">)</span> <span style="color:#75715e">// 满血不能用</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">return</span> <span style="color:#00a8c8">false</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">VFXManager</span><span style="color:#111">.</span><span style="color:#111">PlayVFX</span><span style="color:#111">(</span><span style="color:#111">VFXType</span><span style="color:#111">.</span><span style="color:#111">Healing</span><span style="color:#111">,</span> <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span><span style="color:#111">);</span> <span style="color:#75715e">// 播放音效</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#111">Stats</span><span style="color:#111">.</span><span style="color:#111">ChangeHealth</span><span style="color:#111">(</span> <span style="color:#111">Mathf</span><span style="color:#111">.</span><span style="color:#111">FloorToInt</span><span style="color:#111">(</span><span style="color:#111">HealthPurcentageAmount</span><span style="color:#111">/</span><span style="color:#ae81ff">100.0f</span> <span style="color:#111">*</span> <span style="color:#111">user</span><span style="color:#111">.</span><span style="color:#111">Stats</span><span style="color:#111">.</span><span style="color:#111">stats</span><span style="color:#111">.</span><span style="color:#111">health</span><span style="color:#111">)</span> <span style="color:#111">);</span> <span style="color:#75715e">// 增加血量值，且不超上限</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">return</span> <span style="color:#00a8c8">true</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><h2 id="loot-脚本">Loot 脚本</h2>
<p>以下代码都在 namespace CreatorKitCode 下</p>
<div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">HighlightableObject</span> <span style="color:#111">:</span> <span style="color:#111">MonoBehaviour</span> <span style="color:#75715e">// 边缘高亮</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">protected</span> <span style="color:#111">Renderer</span><span style="color:#111">[]</span> <span style="color:#111">m_Renderers</span><span style="color:#111">;</span> <span style="color:#75715e">// renderer 模块引用</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">int</span> <span style="color:#111">m_RimColorID</span><span style="color:#111">;</span> <span style="color:#75715e">// 参数</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">int</span> <span style="color:#111">m_RimPowID</span><span style="color:#111">;</span> <span style="color:#75715e">// 参数</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">int</span> <span style="color:#111">m_RimIntensityID</span><span style="color:#111">;</span> <span style="color:#75715e">// 参数</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Color</span><span style="color:#111">[]</span> <span style="color:#111">m_OriginalRimColor</span><span style="color:#111">;</span> <span style="color:#75715e">// 原色</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">float</span><span style="color:#111">[]</span> <span style="color:#111">m_SavedRimIntensity</span><span style="color:#111">;</span> <span style="color:#75715e">// 保留</span>
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// gameObject.renderer.material.colo = 会让所有使用该材质的模型都变色，用 MaterialPropertyBlock 来独立控制</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">MaterialPropertyBlock</span> <span style="color:#111">m_PropertyBlock</span><span style="color:#111">;</span> <span style="color:#75715e">// 材质属性代码块，具有相同材质，但属性略有不同的多个对象时可使用</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">protected</span> <span style="color:#00a8c8">virtual</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_Renderers</span> <span style="color:#111">=</span> <span style="color:#111">GetComponentsInChildren</span><span style="color:#111">&lt;</span><span style="color:#111">Renderer</span><span style="color:#111">&gt;();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// shader fixed4 rimLight = _RimColor * pow(saturate(1.0 - dot(worldNormal, worldViewDir)), 1.0 / _RimPower) * _RimIntensity;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_RimColorID</span> <span style="color:#111">=</span> <span style="color:#111">Shader</span><span style="color:#111">.</span><span style="color:#111">PropertyToID</span><span style="color:#111">(</span><span style="color:#d88200">&#34;_RimColor&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 边缘光颜色</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_RimPowID</span> <span style="color:#111">=</span> <span style="color:#111">Shader</span><span style="color:#111">.</span><span style="color:#111">PropertyToID</span><span style="color:#111">(</span><span style="color:#d88200">&#34;_RimPower&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 边缘光衰减</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_RimIntensityID</span> <span style="color:#111">=</span> <span style="color:#111">Shader</span><span style="color:#111">.</span><span style="color:#111">PropertyToID</span><span style="color:#111">(</span><span style="color:#d88200">&#34;_RimIntensity&#34;</span><span style="color:#111">);</span> <span style="color:#75715e">// 边缘光强度</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_PropertyBlock</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">MaterialPropertyBlock</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_OriginalRimColor</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Color</span><span style="color:#111">[</span><span style="color:#111">m_Renderers</span><span style="color:#111">.</span><span style="color:#111">Length</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_SavedRimIntensity</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#00a8c8">float</span><span style="color:#111">[</span><span style="color:#111">m_Renderers</span><span style="color:#111">.</span><span style="color:#111">Length</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">for</span><span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">i</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span> <span style="color:#111">i</span> <span style="color:#111">&lt;</span> <span style="color:#111">m_Renderers</span><span style="color:#111">.</span><span style="color:#111">Length</span><span style="color:#111">;</span> <span style="color:#111">++</span><span style="color:#111">i</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">rend</span> <span style="color:#111">=</span> <span style="color:#111">m_Renderers</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">mat</span> <span style="color:#111">=</span> <span style="color:#111">rend</span><span style="color:#111">.</span><span style="color:#111">sharedMaterial</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">// 如果没有 _RimColor 参数就放弃高亮效果</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">if</span> <span style="color:#111">(!</span><span style="color:#111">mat</span><span style="color:#111">.</span><span style="color:#111">HasProperty</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">))</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>                <span style="color:#111">m_Renderers</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">]</span> <span style="color:#111">=</span> <span style="color:#00a8c8">null</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#00a8c8">continue</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_OriginalRimColor</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">]</span> <span style="color:#111">=</span> <span style="color:#111">mat</span><span style="color:#111">.</span><span style="color:#111">GetColor</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">);</span> <span style="color:#75715e">// 保存原色</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetColor</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">,</span> <span style="color:#111">mat</span><span style="color:#111">.</span><span style="color:#111">GetColor</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">,</span> <span style="color:#111">mat</span><span style="color:#111">.</span><span style="color:#111">GetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimIntensityID</span><span style="color:#111">,</span> <span style="color:#111">mat</span><span style="color:#111">.</span><span style="color:#111">GetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimIntensityID</span><span style="color:#111">));</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">rend</span><span style="color:#111">.</span><span style="color:#111">SetPropertyBlock</span><span style="color:#111">(</span><span style="color:#111">m_PropertyBlock</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Highlight</span><span style="color:#111">()</span> <span style="color:#75715e">// 其它脚本调用高亮</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">for</span> <span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">i</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span> <span style="color:#111">i</span> <span style="color:#111">&lt;</span> <span style="color:#111">m_Renderers</span><span style="color:#111">.</span><span style="color:#111">Length</span><span style="color:#111">;</span> <span style="color:#111">++</span><span style="color:#111">i</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">rend</span> <span style="color:#111">=</span> <span style="color:#111">m_Renderers</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">rend</span> <span style="color:#111">==</span> <span style="color:#00a8c8">null</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>                <span style="color:#00a8c8">continue</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">rend</span><span style="color:#111">.</span><span style="color:#111">GetPropertyBlock</span><span style="color:#111">(</span><span style="color:#111">m_PropertyBlock</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetColor</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">,</span> <span style="color:#111">m_OriginalRimColor</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">]);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">,</span> <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">GetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#ae81ff">0.25f</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_SavedRimIntensity</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">]</span> <span style="color:#111">=</span> <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">GetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimIntensityID</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimIntensityID</span><span style="color:#111">,</span> <span style="color:#ae81ff">1.0f</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">rend</span><span style="color:#111">.</span><span style="color:#111">SetPropertyBlock</span><span style="color:#111">(</span><span style="color:#111">m_PropertyBlock</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Dehighlight</span><span style="color:#111">()</span> <span style="color:#75715e">// 其它脚本调用低亮</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">for</span> <span style="color:#111">(</span><span style="color:#00a8c8">int</span> <span style="color:#111">i</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0</span><span style="color:#111">;</span> <span style="color:#111">i</span> <span style="color:#111">&lt;</span> <span style="color:#111">m_Renderers</span><span style="color:#111">.</span><span style="color:#111">Length</span><span style="color:#111">;</span> <span style="color:#111">++</span><span style="color:#111">i</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">rend</span> <span style="color:#111">=</span> <span style="color:#111">m_Renderers</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">];</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">if</span><span style="color:#111">(</span><span style="color:#111">rend</span> <span style="color:#111">==</span> <span style="color:#00a8c8">null</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>                <span style="color:#00a8c8">continue</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetColor</span><span style="color:#111">(</span><span style="color:#111">m_RimColorID</span><span style="color:#111">,</span> <span style="color:#111">Color</span><span style="color:#111">.</span><span style="color:#111">white</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">,</span> <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">GetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimPowID</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#ae81ff">4.0f</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_PropertyBlock</span><span style="color:#111">.</span><span style="color:#111">SetFloat</span><span style="color:#111">(</span><span style="color:#111">m_RimIntensityID</span><span style="color:#111">,</span> <span style="color:#111">m_SavedRimIntensity</span><span style="color:#111">[</span><span style="color:#111">i</span><span style="color:#111">]);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">rend</span><span style="color:#111">.</span><span style="color:#111">SetPropertyBlock</span><span style="color:#111">(</span><span style="color:#111">m_PropertyBlock</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">InteractableObject</span> <span style="color:#111">:</span> <span style="color:#111">HighlightableObject</span> <span style="color:#75715e">// 继承自可以高亮类</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">IsInteractable</span> <span style="color:#111">{</span> <span style="color:#00a8c8">get</span><span style="color:#111">;</span> <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">abstract</span> <span style="color:#00a8c8">void</span> <span style="color:#111">InteractWith</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">target</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="color:#272822;background-color:#fafafa;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-cs" data-lang="cs"><span style="display:flex;"><span><span style="color:#00a8c8">public</span> <span style="color:#00a8c8">class</span> <span style="color:#75af00">Loot</span> <span style="color:#111">:</span> <span style="color:#111">InteractableObject</span> <span style="color:#75715e">// 继承自可以互动类</span>
</span></span><span style="display:flex;"><span><span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">static</span> <span style="color:#00a8c8">float</span> <span style="color:#111">AnimationTime</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0.5f</span><span style="color:#111">;</span> <span style="color:#75715e">// 动画总时间</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#111">Item</span> <span style="color:#111">Item</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">bool</span> <span style="color:#111">IsInteractable</span> <span style="color:#111">=&gt;</span> <span style="color:#111">m_AnimationTimer</span> <span style="color:#111">&gt;=</span> <span style="color:#111">AnimationTime</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Vector3</span> <span style="color:#111">m_OriginalPosition</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">Vector3</span> <span style="color:#111">m_TargetPoint</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">float</span> <span style="color:#111">m_AnimationTimer</span> <span style="color:#111">=</span> <span style="color:#ae81ff">0.0f</span><span style="color:#111">;</span> <span style="color:#75715e">// 当前动画时间</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">void</span> <span style="color:#111">Awake</span><span style="color:#111">()</span> <span style="color:#75715e">// 不论是否激活，都执行一次</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_OriginalPosition</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_TargetPoint</span> <span style="color:#111">=</span> <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">m_AnimationTimer</span> <span style="color:#111">=</span> <span style="color:#111">AnimationTime</span> <span style="color:#111">-</span> <span style="color:#ae81ff">0.1f</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">protected</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">void</span> <span style="color:#111">Start</span><span style="color:#111">()</span> <span style="color:#75715e">// 激活后，都执行一次</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">base</span><span style="color:#111">.</span><span style="color:#111">Start</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">CreateWorldRepresentation</span><span style="color:#111">();</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">void</span> <span style="color:#111">Update</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">if</span> <span style="color:#111">(</span><span style="color:#111">m_AnimationTimer</span> <span style="color:#111">&lt;</span> <span style="color:#111">AnimationTime</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">m_AnimationTimer</span> <span style="color:#111">+=</span> <span style="color:#111">Time</span><span style="color:#111">.</span><span style="color:#111">deltaTime</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">// Mathf.Clamp01：把value的值限定在0和1之间并返回value。如果value小于0，返回0。如果value大于1,返回1;否则返回value。</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">float</span> <span style="color:#111">ratio</span> <span style="color:#111">=</span> <span style="color:#111">Mathf</span><span style="color:#111">.</span><span style="color:#111">Clamp01</span><span style="color:#111">(</span><span style="color:#111">m_AnimationTimer</span> <span style="color:#111">/</span> <span style="color:#111">AnimationTime</span><span style="color:#111">);</span> <span style="color:#75715e">// 动画进度</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">// Vector3.Lerp：对两个点进行插值</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">Vector3</span> <span style="color:#111">currentPos</span> <span style="color:#111">=</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">Lerp</span><span style="color:#111">(</span><span style="color:#111">m_OriginalPosition</span><span style="color:#111">,</span> <span style="color:#111">m_TargetPoint</span><span style="color:#111">,</span> <span style="color:#111">ratio</span><span style="color:#111">);</span> <span style="color:#75715e">// 补间</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">currentPos</span><span style="color:#111">.</span><span style="color:#111">y</span> <span style="color:#111">=</span> <span style="color:#111">currentPos</span><span style="color:#111">.</span><span style="color:#111">y</span> <span style="color:#111">+</span> <span style="color:#111">Mathf</span><span style="color:#111">.</span><span style="color:#111">Sin</span><span style="color:#111">(</span><span style="color:#111">ratio</span> <span style="color:#111">*</span> <span style="color:#111">Mathf</span><span style="color:#111">.</span><span style="color:#111">PI</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#ae81ff">2.0f</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">position</span> <span style="color:#111">=</span> <span style="color:#111">currentPos</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">if</span> <span style="color:#111">(</span><span style="color:#111">m_AnimationTimer</span> <span style="color:#111">&gt;=</span> <span style="color:#111">AnimationTime</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>                <span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    public void NewLoot(Loot loot)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        Vector3 screenPos;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        if (OnScreen(loot.transform.position, out screenPos))
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                            AddButton(loot, screenPos);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        else
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                            m_OffScreenLoot.Add(loot);
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                 */</span>
</span></span><span style="display:flex;"><span>                <span style="color:#111">LootUI</span><span style="color:#111">.</span><span style="color:#111">Instance</span><span style="color:#111">.</span><span style="color:#111">NewLoot</span><span style="color:#111">(</span><span style="color:#00a8c8">this</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#75715e">// 在 Scene 中画线：起点，终点，颜色</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Debug</span><span style="color:#111">.</span><span style="color:#111">DrawLine</span><span style="color:#111">(</span><span style="color:#111">m_TargetPoint</span><span style="color:#111">,</span> <span style="color:#111">m_TargetPoint</span> <span style="color:#111">+</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">up</span><span style="color:#111">,</span> <span style="color:#111">Color</span><span style="color:#111">.</span><span style="color:#111">magenta</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">public</span> <span style="color:#00a8c8">override</span> <span style="color:#00a8c8">void</span> <span style="color:#111">InteractWith</span><span style="color:#111">(</span><span style="color:#111">CharacterData</span> <span style="color:#111">target</span><span style="color:#111">)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">target</span><span style="color:#111">.</span><span style="color:#111">Inventory</span><span style="color:#111">.</span><span style="color:#111">AddItem</span><span style="color:#111">(</span><span style="color:#111">Item</span><span style="color:#111">);</span> <span style="color:#75715e">// 角色背包加入物品</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">SFXManager</span><span style="color:#111">.</span><span style="color:#111">PlaySound</span><span style="color:#111">(</span><span style="color:#111">SFXManager</span><span style="color:#111">.</span><span style="color:#111">Use</span><span style="color:#111">.</span><span style="color:#111">Sound2D</span><span style="color:#111">,</span> <span style="color:#00a8c8">new</span> <span style="color:#111">SFXManager</span><span style="color:#111">.</span><span style="color:#111">PlayData</span><span style="color:#111">(){</span><span style="color:#111">Clip</span> <span style="color:#111">=</span> <span style="color:#111">SFXManager</span><span style="color:#111">.</span><span style="color:#111">PickupSound</span><span style="color:#111">});</span> <span style="color:#75715e">// 播放音效</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">UISystem</span><span style="color:#111">.</span><span style="color:#111">Instance</span><span style="color:#111">.</span><span style="color:#111">InventoryWindow</span><span style="color:#111">.</span><span style="color:#111">Load</span><span style="color:#111">(</span><span style="color:#111">target</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">Destroy</span><span style="color:#111">(</span><span style="color:#111">gameObject</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#00a8c8">void</span> <span style="color:#111">CreateWorldRepresentation</span><span style="color:#111">()</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">if</span> <span style="color:#111">(</span><span style="color:#111">Item</span><span style="color:#111">.</span><span style="color:#111">WorldObjectPrefab</span> <span style="color:#111">!=</span> <span style="color:#00a8c8">null</span><span style="color:#111">)</span> <span style="color:#75715e">// 如果有 WorldObjectPrefab 就用</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">obj</span> <span style="color:#111">=</span> <span style="color:#111">Instantiate</span><span style="color:#111">(</span><span style="color:#111">Item</span><span style="color:#111">.</span><span style="color:#111">WorldObjectPrefab</span><span style="color:#111">,</span> <span style="color:#111">transform</span><span style="color:#111">,</span> <span style="color:#00a8c8">false</span><span style="color:#111">);</span> <span style="color:#75715e">// 第三个参数 worldPositionStays 是否为世界坐标</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">obj</span><span style="color:#111">.</span><span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">localPosition</span> <span style="color:#111">=</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">zero</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">obj</span><span style="color:#111">.</span><span style="color:#111">layer</span> <span style="color:#111">=</span> <span style="color:#111">LayerMask</span><span style="color:#111">.</span><span style="color:#111">NameToLayer</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Interactable&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>        <span style="color:#00a8c8">else</span> <span style="color:#111">{</span> <span style="color:#75715e">// 没有，就创建一个名为 ItemBillboard 的物体，添加精灵</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">GameObject</span> <span style="color:#111">billboard</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">GameObject</span><span style="color:#111">(</span><span style="color:#d88200">&#34;ItemBillboard&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">SetParent</span><span style="color:#111">(</span><span style="color:#111">transform</span><span style="color:#111">,</span> <span style="color:#00a8c8">false</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">localPosition</span> <span style="color:#111">=</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">up</span> <span style="color:#111">*</span> <span style="color:#ae81ff">0.3f</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">layer</span> <span style="color:#111">=</span> <span style="color:#111">LayerMask</span><span style="color:#111">.</span><span style="color:#111">NameToLayer</span><span style="color:#111">(</span><span style="color:#d88200">&#34;Interactable&#34;</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">renderer</span> <span style="color:#111">=</span> <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">AddComponent</span><span style="color:#111">&lt;</span><span style="color:#111">SpriteRenderer</span><span style="color:#111">&gt;();</span>
</span></span><span style="display:flex;"><span>            <span style="color:#75715e">/*
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                public class ResourceManager : MonoBehaviour
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    public static ResourceManager Instance { get; private set; }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    public Material BillboardMaterial =&gt; m_BillboardMaterial;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            #pragma warning disable CS0649  
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    [SerializeField]
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    Material m_BillboardMaterial;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">            #pragma warning restore CS0649 
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    void Awake() {
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                        Instance = this;
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                    }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">                }
</span></span></span><span style="display:flex;"><span><span style="color:#75715e">             */</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">renderer</span><span style="color:#111">.</span><span style="color:#111">sharedMaterial</span> <span style="color:#111">=</span> <span style="color:#111">ResourceManager</span><span style="color:#111">.</span><span style="color:#111">Instance</span><span style="color:#111">.</span><span style="color:#111">BillboardMaterial</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">renderer</span><span style="color:#111">.</span><span style="color:#111">sprite</span> <span style="color:#111">=</span> <span style="color:#111">Item</span><span style="color:#111">.</span><span style="color:#111">ItemSprite</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">rect</span> <span style="color:#111">=</span> <span style="color:#111">Item</span><span style="color:#111">.</span><span style="color:#111">ItemSprite</span><span style="color:#111">.</span><span style="color:#111">rect</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">float</span> <span style="color:#111">maxSize</span> <span style="color:#111">=</span> <span style="color:#111">rect</span><span style="color:#111">.</span><span style="color:#111">width</span> <span style="color:#111">&gt;</span> <span style="color:#111">rect</span><span style="color:#111">.</span><span style="color:#111">height</span> <span style="color:#111">?</span> <span style="color:#111">rect</span><span style="color:#111">.</span><span style="color:#111">width</span> <span style="color:#111">:</span> <span style="color:#111">rect</span><span style="color:#111">.</span><span style="color:#111">height</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">float</span> <span style="color:#111">scale</span> <span style="color:#111">=</span> <span style="color:#111">Item</span><span style="color:#111">.</span><span style="color:#111">ItemSprite</span><span style="color:#111">.</span><span style="color:#111">pixelsPerUnit</span> <span style="color:#111">/</span> <span style="color:#111">maxSize</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">transform</span><span style="color:#111">.</span><span style="color:#111">localScale</span> <span style="color:#111">=</span> <span style="color:#111">scale</span> <span style="color:#111">*</span> <span style="color:#111">Vector3</span><span style="color:#111">.</span><span style="color:#111">one</span> <span style="color:#111">*</span> <span style="color:#ae81ff">0.5f</span><span style="color:#111">;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#00a8c8">var</span> <span style="color:#111">bc</span> <span style="color:#111">=</span> <span style="color:#111">billboard</span><span style="color:#111">.</span><span style="color:#111">AddComponent</span><span style="color:#111">&lt;</span><span style="color:#111">BoxCollider</span><span style="color:#111">&gt;();</span> <span style="color:#75715e">// 碰撞体</span>
</span></span><span style="display:flex;"><span>            <span style="color:#111">bc</span><span style="color:#111">.</span><span style="color:#111">size</span> <span style="color:#111">=</span> <span style="color:#00a8c8">new</span> <span style="color:#111">Vector3</span><span style="color:#111">(</span><span style="color:#ae81ff">0.5f</span><span style="color:#111">,</span> <span style="color:#ae81ff">0.5f</span><span style="color:#111">,</span> <span style="color:#ae81ff">0.5f</span><span style="color:#111">)</span> <span style="color:#111">*</span> <span style="color:#111">(</span><span style="color:#ae81ff">1.0f</span><span style="color:#111">/</span><span style="color:#111">scale</span><span style="color:#111">);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#111">}</span>
</span></span><span style="display:flex;"><span><span style="color:#111">}</span>
</span></span></code></pre></div>

    


                    
                    <div class="row"></div> 

                </div>

            </div> 

        </div> 
<script src="/lib/jquery.min.js"></script> 
<script src="/lib/popper.min.js"></script> 

<script src="/js/bootstrap.min.js"></script> 


<script type="text/javascript" src="/plugins/lunr.min.js"></script>
<script type="text/javascript" src="/plugins/auto-complete.js"></script>
<link href="/plugins/auto-complete.css" rel="stylesheet">
<script type="text/javascript">
  
      var baseurl = "\/";
  
</script>
<script type="text/javascript" src="/plugins/search.js"></script>

<script type="text/javascript" src="/plugins/favorites.js"></script>


<script type="text/javascript" src="/plugins/clipboard.js"></script>
<script>
  new ClipboardJS('.btn');
</script>
</body>
</html>
